const baseUrl = 'http://localhost:8080';
//带Token请求
const httpTokenRequest = (opts) => {
	let token = '';
	//从stroage拿出token
	uni.getStorage({
		key: 'token',
		success: (ress) => {
			token = "Bearer " + ress.data
		}
	});
	//此token是登录成功后后台返回保存在storage中的
	let httpDefaultOpts = {
		url: baseUrl + opts.url,
		data: opts.data || {},
		method: opts.method || "get",
		header: token == '' ? {
			"Content-Type": "application/json; charset=UTF-8"
		} : {
			'Authorization': token,
			"Content-Type": "application/json; charset=UTF-8"
		},
		dataType: 'json'
	}
	let promise = new Promise((resolve, reject) => {
		uni.request(httpDefaultOpts).then(
			res => {
				resolve(res[1].data);
			}
		).catch(
			response => {
				reject(response);
			}
		)
	})
	return promise
};
export default httpTokenRequest;
